import json

from bs4 import BeautifulSoup
from loguru import logger

from com.arcfox.manager.redis_task_manager import RedisTaskManager
from com.arcfox.school.processor.base_processor import BaseProcessor
from com.arcfox.middleware import async_mysql_middleware as db
from com.arcfox.util.muilty_coroutine_util import concurrency


class YifenYiduanProcessor(BaseProcessor):

    def __init__(self):
        super().__init__()

    @concurrency(5)
    async def store_yifen_yiduan(self, **result):
        task = result['task']
        mapping = db.MysqlMapping("tb_score_segment")
        exist = await mapping.query(
            {
                "province": task.get("province"),
                "score_year": task.get("score_year"),
                "score": task.get("score"),
                "score_category": task.get("score_category"),
                "edu_level": task.get("edu_level"),
            }, ["id"])
        if exist:
            logger.info(" 已经存在{}", exist)
            return
        await mapping.insert(task)
